<?php
include_once "xAP-functions/webincludes.php";
echo webpageheader();



$now=date("Y-m-d H:i:s");

// get count of events for each source
$sql="select count(EventLinkID) as EventCount, EventSourceID from xAP_EventLink  group by EventSourceID";
$results=dbquery($sql);
foreach($results as $row){
	$count[$row["EventSourceID"]]=$row["EventCount"];
}



// get the sources
$sql="select xAP_EventSource.EventSourceID,
xAP_EventSource.Section,
xAP_EventSource.Source,
xAP_EventSource.SourceDesc 
from xAP_EventSource
";
if($_GET["section"]!=""){
	$sql.=" where Section='".dbesc($_GET["section"])."' ";
}
$sql.=" order by Section,Source";
$results=dbquery($sql);

//display
echo "<table width=100%>
<TR><TD class='boldtext'>Module</td>
<TD class='boldtext'>Type</td>
<TD class='boldtext'>Description</td>
<TD class='boldtext'>Events</td>
<td></td></tr>";
foreach($results as $row){
	echo "<tr>
	<TD class='normaltext'>".$row["Section"]."</td>
	<TD class='normaltext'>".$row["Source"]."</td>
	<TD class='normalsmalltext'>".$row["SourceDesc"]."</td>
	<TD class='normaltext'>".intval($count[$row["EventSourceID"]])."</td>
	<TD class='normaltext'>
	<a href='source_edit.php?id=".$row["EventSourceID"]."&section=".dbesc($_GET["section"])."'>Edit</a>
	</td>
	</tr>";
	echo "<TR bgcolor='#dddddd'><td colspan=4 height=1></td></tr>";
}


echo "</table>";

echo webpagefooter();
?>